package com.yixincaipiao.ui.account;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import android.view.View;

import com.android.volley.VolleyError;
import com.yixincaipiao.R;
import com.yixincaipiao.base.BaseActivity;
import com.yixincaipiao.common.CommonConfig;
import com.yixincaipiao.exception.BaseException;
import com.yixincaipiao.network.Http;
import com.yixincaipiao.network.NetRequest;
import com.yixincaipiao.ui.account.modle.User;
import com.yixincaipiao.ui.main.MainActivity;
import com.yixincaipiao.utils.JsonUtil;
import com.yixincaipiao.weight.Dialogs;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/4/25.
 */

public class LoginActivity extends BaseActivity implements View.OnClickListener {
    private static int mFlag = 0;
    String name = "18813155458";
    String pass = "d05faede6822635cb1559ff04592bb05";

    public static void actionView(Context context, int flag) {
        mFlag = flag;
        context.startActivity(new Intent(context, LoginActivity.class));
    }

    @Override
    protected void initView() {
        setContentView(R.layout.login_layout);
        findViewById(R.id.btn_login).setOnClickListener(this);

    }

    @Override
    protected void getData() {

    }

    @Override
    public void onClick(View v) {
        String url = "http://www.dyxstar.com/app/yxq/Api/Login/login";
        Map<String, Object> params = new HashMap<>();
        params.put("mobile", name);
        params.put("passwd", pass);
        Http.aSyncPost(this, Dialogs.getWaitDialog(this), url, params, new NetRequest.NetRequestListener() {
            @Override
            public void onAccessComplete(boolean success, String object, VolleyError error, String flag) {

                try {
                    String resultData = Http._analysData(object);
                    Account.Instance(getApplicationContext()).saveUser(resultData);

                    Log.i("after", "返回数据               " + Account.Instance(getApplicationContext()).getUser().toString());
                    MainActivity.actionView(LoginActivity.this,0);
                    finish();
                } catch (BaseException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
